// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class Player extends cc.Component {

    @property(cc.Sprite)
    player: cc.Sprite = null;
    @property(cc.Node)
    bg:cc.Node=null;
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.bg.on(cc.Node.EventType.TOUCH_END,this.onClick,this);
    }

    start () {

    }
    onClick(e:cc.Event.EventTouch){
        let p=e.getLocation();
        let act=cc.moveTo(1200,p.x-cc.view.getCanvasSize().width*0.5,p.y-cc.view.getCanvasSize().height*0.5)
        this.player.node.runAction(act);
        
        // this.player.node.setPosition(this.player.node.x+Math.random()*10-5,this.player.node.y+Math.random()*10-5);
    }
    // update (dt) {}
}
